import requests
from urllib.parse import urlparse
import re
import csv
f = open('data.csv', mode='w', newline='')
csvwrter = csv.writer(f)
for i in range(1,6):
    with open(f'api_version_accessbiliby-{i}.txt', encoding='utf-8') as file:
        content = file.read()

    obj = re.compile(r'.*?"api_title": "(?P<name>.*?)",.*?"visit_url": "(?P<URL>.*?)",.*?API Portal / Home Page', re.S)
    result = obj.finditer(content)
    for it in result:
        print(it.group("URL"), '\t')
        print(it.group("name"), '\t')
        host = urlparse(it.group("URL")).hostname
        data = [host, it.group("name")]
        csvwrter.writerow(data)
f.close()